package com.esperia09.webservice.mixibot.oauth;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet {
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		resp.setContentType("text/plain");
		// resp.getWriter().println("Hello, world");
		
		resp.sendRedirect(createAuthorizeUrl("r_voice%20w_voice"));
	}
	
	private String createAuthorizeUrl(String permissionStr) {
		String consumerKey = System.getProperty(OAuthConstants.MIXI_CONSUMER_KEY);
		
		String authUrl = OAuthConstants.MIXI_AURHORIZE_URL
			+ "?client_id=" + consumerKey
			+ "&response_type=code"
			+ "&scope=" + permissionStr
			+ "&display=pc"
			// + "&state="
			;
		return authUrl;
	}
}
